﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	internal class AnalysisStruct
	{
		public static void SignRegion(Autodesk.Revit.DB.Document doc, List<RectStruct> lstRect, Category lineCategory)
		{
			foreach (RectStruct rectStruct in lstRect)
			{
				int num = 1;
				foreach (Curve curve in rectStruct.LstCurve)
				{
					if (!(curve == null))
					{
						doc.GetTextNode(doc.ActiveView, AnalysisStruct.GetCenterPoint(curve), new XYZ(1.0, 0.0, 0.0), new XYZ(0.0, 1.0, 0.0), 1.0, (Autodesk.Revit.DB.TextAlignFlags)1152, rectStruct.nId.ToString() + ":" + num);
						GroundStorehouseNozzle.DrawCurve(doc.ActiveView, doc, curve, lineCategory);
						num++;
					}
				}
			}
		}

		private static XYZ GetCenterPoint(Curve lst)
		{
			new XYZ(0.0, 0.0, 0.0);
			XYZ endPoint = lst.GetEndPoint(0);
			XYZ endPoint2 = lst.GetEndPoint(1);
			return (endPoint + endPoint2) / 2.0;
		}

		public static List<List<Curve>> GetLstSignArea(Autodesk.Revit.DB.Document doc, Category lineCategory, List<RectStruct> lstRect, List<Element> lstElemS)
		{
			GroundStorehouseNozzle groundStorehouseNozzle = new GroundStorehouseNozzle();
			List<Element> list = new List<Element>();
			List<Element> list2 = new List<Element>();
			foreach (Element element in lstElemS)
			{
				SprinklerInfo sprinklerInfo = new SprinklerInfo();
				sprinklerInfo.CollisionEle = element;
				sprinklerInfo.AroundSprinklers = GroundStorehouseNozzle.GetNearSprinklers(doc, element);
				Element item = null;
				if (!groundStorehouseNozzle.JudgeDistanceIsSatisfy1(sprinklerInfo, (element.Location as LocationPoint).Point, out item))
				{
					list.Add(element);
					list2.Add(item);
				}
			}
			List<List<Curve>> list3 = new List<List<Curve>>();
			double num = 0.65616797900262469;
			for (int i = 0; i < list.Count; i++)
			{
				XYZ point = (list[i].Location as LocationPoint).Point;
				XYZ point2 = (list2[i].Location as LocationPoint).Point;
				XYZ xyz = (point - point2).Normalize();
				XYZ xyz2 = (point2 - point).Normalize();
				XYZ item2 = point2 + num * xyz2;
				XYZ item3 = point + num * xyz;
				List<XYZ> list4 = new List<XYZ>();
				list4.Add(item2);
				list4.Add(item3);
				IList<XYZ> list5 = new List<XYZ>();
				IList<XYZ> list6 = new List<XYZ>();
				GroundStorehouseNozzle.OffsetCurve(list4, num * 2.0, out list5, 0.0);
				GroundStorehouseNozzle.OffsetCurve(list4, -num * 2.0, out list6, 0.0);
				list3.Add(new List<Curve>
				{
					Line.CreateBound(list5[0], list5[1]),
					Line.CreateBound(list5[1], list6[1]),
					Line.CreateBound(list6[1], list6[0]),
					Line.CreateBound(list6[0], list5[0])
				});
			}
			for (int j = 0; j < list3.Count; j++)
			{
				if (list3[j].Count != 2)
				{
					for (int k = 0; k < list3[j].Count; k++)
					{
						Curve curve = list3[j][k];
						GroundStorehouseNozzle.DrawCurve(doc.ActiveView, doc, curve, lineCategory);
					}
				}
			}
			return list3;
		}

		public static List<XYZ> AllSprinklerLayPoints(Autodesk.Revit.DB.Document doc, List<RectStruct> lstRect, List<List<Curve>> InnerCurve)
		{
			List<Element> list = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Parking).OfClass(typeof(FamilyInstance)).ToElements().ToList<Element>();
			List<FamilyInstance> list2 = new List<FamilyInstance>();
			foreach (Element element in list)
			{
				list2.Add(element as FamilyInstance);
			}
			new List<XYZ>();
			List<XYZ> list3 = new List<XYZ>();
			IEnumerable<RectStruct> enumerable = from n in lstRect
			where !n.blRect
			select n;
			IEnumerable<RectStruct> enumerable2 = from n in lstRect
			where n.blRect
			select n;
			GroundStorehouseNozzle groundStorehouseNozzle = new GroundStorehouseNozzle();
			List<List<Curve>> list4 = new List<List<Curve>>();
			foreach (RectStruct rectStruct in enumerable2)
			{
				if (rectStruct.LstCurve.Count != 4)
				{
					list4.Add(rectStruct.LstCurve);
				}
				else
				{
					List<XYZ> list5 = new List<XYZ>();
					FamilyInstance familyInstance = null;
					List<Curve> lstParking = AnalysisStruct.IsListCurveParking(doc.ActiveView.GenLevel, rectStruct.LstCurve, list2, out familyInstance);
					list5 = AnalysisStruct.GetLstCurvePoint(rectStruct.LstCurve, lstParking);
					if (list5 == null)
					{
						list4.Add(rectStruct.LstCurve);
					}
					else if (list5.Count > 0)
					{
						list3.AddRange(list5);
					}
				}
			}
			List<XYZ> list6 = new List<XYZ>();
			foreach (RectStruct rectStruct2 in enumerable)
			{
				if (rectStruct2.LstCurve.Count != 2)
				{
					List<Curve> ruleRectangle = groundStorehouseNozzle.NotRuleRoomChangeRule(rectStruct2.LstCurve);
					List<List<Curve>> allCloseCurves = groundStorehouseNozzle.GetAllCloseCurves(rectStruct2.LstCurve);
					List<XYZ> list7 = groundStorehouseNozzle.CalculateSprinklersPoints(ruleRectangle);
					if (list7 != null)
					{
						if (allCloseCurves.Count == 0)
						{
							list6.AddRange(list7);
						}
						else
						{
							foreach (XYZ xyz in list7)
							{
								if (allCloseCurves[0].Count > 0 && GroundStorehouseNozzle.PointInPloygon(allCloseCurves[0], xyz) != -1)
								{
									bool flag = false;
									using (List<XYZ>.Enumerator enumerator4 = list6.GetEnumerator())
									{
										while (enumerator4.MoveNext())
										{
											if (enumerator4.Current.DistanceTo(xyz) < 1.0)
											{
												flag = true;
											}
										}
									}
									if (!flag)
									{
										list6.Add(xyz);
									}
								}
							}
						}
					}
				}
			}
			list3.AddRange(list6);
			if (InnerCurve.Count == 1)
			{
				return list3;
			}
			List<XYZ> list8 = new List<XYZ>();
			foreach (XYZ xyz2 in list3)
			{
				for (int i = 0; i < InnerCurve.Count - 1; i++)
				{
					if (GroundStorehouseNozzle.PointInPloygon(InnerCurve[i], xyz2) != 1)
					{
						list8.Add(xyz2);
					}
				}
			}
			return list8;
		}

		private static List<XYZ> GetLstCurvePoint(List<Curve> lstCurve, List<Curve> lstParking)
		{
			return new List<XYZ>();
		}

		public static List<Curve> MergeCurve(List<Curve> firstMerge, List<Curve> secondMerge)
		{
			List<Curve> list = new List<Curve>();
			list.AddRange(firstMerge);
			list.AddRange(secondMerge);
			GroundStorehouseNozzle.RemoveRepeatCurves(ref list);
			if (list.Count == 4)
			{
				return list;
			}
			List<Curve> list2 = new List<Curve>();
			if (list.Count < 3)
			{
				return list2;
			}
			foreach (Curve curve in firstMerge)
			{
				YJKLine hyline = new YJKLine(curve.GetEndPoint(0), curve.GetEndPoint(1));
				foreach (Curve curve2 in secondMerge)
				{
					XYZ endPoint = (curve2 as Line).GetEndPoint(0);
					XYZ endPoint2 = (curve2 as Line).GetEndPoint(1);
					YJKLine secondLine = new YJKLine(endPoint, endPoint2);
					XYZ endPoint3 = curve.GetEndPoint(0);
					XYZ endPoint4 = curve.GetEndPoint(1);
					if (Math.Abs(curve.Length - curve2.Length) >= 1E-05 || ((endPoint3.DistanceTo(endPoint) >= 0.0001 || endPoint4.DistanceTo(endPoint2) >= 0.0001) && (endPoint3.DistanceTo(endPoint2) >= 0.0001 || endPoint4.DistanceTo(endPoint) >= 0.0001)))
					{
						List<Line> list3 = new List<Line>();
						list3.Add(curve as Line);
						list3.Add(curve2 as Line);
						if (hyline.IsParallel(curve2 as Line) && AnalysisStruct.IsClosingToClosing(hyline, secondLine))
						{
							List<XYZ> list4 = new List<XYZ>();
							list4.Add(curve.GetEndPoint(0));
							list4.Add(curve.GetEndPoint(1));
							list4.Add(curve2.GetEndPoint(0));
							list4.Add(curve2.GetEndPoint(1));
							list.Remove(curve);
							list.Remove(curve2);
							List<XYZ> farestTwoPoints = AnalysisStruct.GetFarestTwoPoints(list4);
							if (farestTwoPoints.Count == 2)
							{
								Curve item = Line.CreateBound(farestTwoPoints[0], farestTwoPoints[1]);
								list2.Add(item);
								break;
							}
						}
					}
				}
			}
			list2.AddRange(list);
			if (list2.Count == 4)
			{
				return list2;
			}
			return null;
		}

		public static List<XYZ> GetFarestTwoPoints(List<XYZ> points)
		{
			List<XYZ> list = new List<XYZ>();
			double num = 0.0;
			XYZ item = XYZ.Zero;
			XYZ item2 = XYZ.Zero;
			for (int i = 0; i < points.Count - 1; i++)
			{
				for (int j = i + 1; j < points.Count; j++)
				{
					if (points[i].DistanceTo(points[j]) > num)
					{
						num = points[i].DistanceTo(points[j]);
						item = points[i];
						item2 = points[j];
					}
				}
			}
			list.Add(item);
			list.Add(item2);
			return list;
		}

		private static bool IsClosingToClosing(YJKLine lineFirst, YJKLine secondLine)
		{
			XYZ startPoint = lineFirst.StartPoint;
			XYZ endPoint = lineFirst.EndPoint;
			XYZ startPoint2 = secondLine.StartPoint;
			XYZ endPoint2 = secondLine.EndPoint;
			return startPoint.IsAlmostEqualTo(startPoint2, 0.001) || startPoint.IsAlmostEqualTo(endPoint2, 0.001) || endPoint.IsAlmostEqualTo(startPoint2, 0.001) || endPoint.IsAlmostEqualTo(endPoint2, 0.001);
		}

		public static void Merge(List<RectStruct> lstRect, out List<RectStruct> listOut)
		{
			listOut = new List<RectStruct>();
			int num = lstRect.Count;
			List<RectStruct> list = new List<RectStruct>();
			List<int> list2 = new List<int>();
			List<RectStruct> list3 = new List<RectStruct>();
			foreach (RectStruct rectStruct in lstRect)
			{
				if (!rectStruct.blMerge)
				{
					list3.Add(rectStruct);
				}
				else
				{
					int num2 = 1;
					for (int i = 0; i < rectStruct.nSign.Count; i++)
					{
						if (rectStruct.nSign[i] == 1)
						{
							switch (num2)
							{
							case 1:
							{
								int upRect = rectStruct.UpRect;
								RectStruct rectStruct2 = AnalysisStruct.MergeRectStruct(list2, lstRect, upRect, rectStruct, num);
								if (rectStruct2 != null)
								{
									AnalysisStruct.UpdateRectStruct(1, upRect, rectStruct2, rectStruct, lstRect, ref list2);
									num++;
									list.Add(rectStruct2);
								}
								else
								{
									rectStruct.blMerge = false;
								}
								break;
							}
							case 2:
							{
								int downRect = rectStruct.DownRect;
								RectStruct rectStruct2 = AnalysisStruct.MergeRectStruct(list2, lstRect, downRect, rectStruct, num);
								if (rectStruct2 != null)
								{
									AnalysisStruct.UpdateRectStruct(2, downRect, rectStruct2, rectStruct, lstRect, ref list2);
									num++;
									list.Add(rectStruct2);
								}
								else
								{
									rectStruct.blMerge = false;
								}
								break;
							}
							case 3:
							{
								int leftRect = rectStruct.LeftRect;
								RectStruct rectStruct2 = AnalysisStruct.MergeRectStruct(list2, lstRect, leftRect, rectStruct, num);
								if (rectStruct2 != null)
								{
									AnalysisStruct.UpdateRectStruct(3, leftRect, rectStruct2, rectStruct, lstRect, ref list2);
									num++;
									list.Add(rectStruct2);
								}
								else
								{
									rectStruct.blMerge = false;
								}
								break;
							}
							case 4:
							{
								int rightRect = rectStruct.RightRect;
								RectStruct rectStruct2 = AnalysisStruct.MergeRectStruct(list2, lstRect, rightRect, rectStruct, num);
								if (rectStruct2 != null)
								{
									AnalysisStruct.UpdateRectStruct(4, rightRect, rectStruct2, rectStruct, lstRect, ref list2);
									num++;
									list.Add(rectStruct2);
								}
								else
								{
									rectStruct.blMerge = false;
								}
								break;
							}
							}
						}
						num2++;
					}
				}
			}
			using (List<int>.Enumerator enumerator2 = list2.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					int item = enumerator2.Current;
					IEnumerable<RectStruct> source = from n in lstRect
					where n.nId == item
					select n;
					if (source.Count<RectStruct>() > 0)
					{
						lstRect.Remove(source.First<RectStruct>());
					}
				}
			}
			if (list3.Count == lstRect.Count)
			{
				listOut = lstRect;
				return;
			}
			lstRect.AddRange(list);
			AnalysisStruct.Merge(lstRect, out listOut);
		}

		private static RectStruct MergeRectStruct(List<int> lstRectDel, List<RectStruct> lstRect, int id, RectStruct item, int TotalId)
		{
			if (lstRectDel.Contains(item.nId))
			{
				return null;
			}
			IEnumerable<RectStruct> source = from n in lstRect
			where n.nId == id
			select n;
			if (source.Count<RectStruct>() <= 0)
			{
				return null;
			}
			List<Curve> list = new List<Curve>();
			list.AddRange(source.First<RectStruct>().LstCurve);
			list.AddRange(item.LstCurve);
			List<Curve> list2 = AnalysisStruct.MergeCurve(source.First<RectStruct>().LstCurve, item.LstCurve);
			if (list2.Count != 4)
			{
				return null;
			}
			RectStruct rectStruct = new RectStruct();
			rectStruct.nId = TotalId + 1;
			rectStruct.blRect = GroundStorehouseNozzle.GetBlRect(list2);
			rectStruct.blMerge = GroundStorehouseNozzle.GetBlLess(list2);
			List<Curve> lstCurve = new List<Curve>();
			rectStruct.nSign = AnalysisStruct.AnaUDLR(list2, out lstCurve);
			rectStruct.LstCurve = lstCurve;
			return rectStruct;
		}

		private static void UpdateRectStruct(int NorId, int MergeId, RectStruct structRectMerge, RectStruct structRect, List<RectStruct> lstRect, ref List<int> lstRectDel)
		{
			List<int> list = new List<int>();
			list.Add(0);
			list.Add(0);
			list.Add(0);
			list.Add(0);
			lstRectDel = new List<int>();
			lstRectDel.Add(structRect.nId);
			lstRectDel.Add(MergeId);
			IEnumerable<RectStruct> source = from n in lstRect
			where n.nId == MergeId
			select n;
			if (source.Count<RectStruct>() == 0)
			{
				return;
			}
			RectStruct rectStruct = source.First<RectStruct>();
			structRectMerge.nSign = structRect.nSign;
			if (NorId == 1)
			{
				rectStruct.DownRect = structRectMerge.nId;
				structRectMerge.UpRect = rectStruct.nId;
				structRectMerge.nSign[0] = rectStruct.nSign[1];
			}
			if (NorId == 2)
			{
				rectStruct.UpRect = structRectMerge.nId;
				structRectMerge.DownRect = rectStruct.nId;
				structRectMerge.nSign[1] = rectStruct.nSign[0];
			}
			if (NorId == 3)
			{
				rectStruct.RightRect = structRectMerge.nId;
				structRectMerge.LeftRect = rectStruct.nId;
				structRectMerge.nSign[2] = rectStruct.nSign[3];
			}
			if (NorId == 4)
			{
				rectStruct.LeftRect = structRectMerge.nId;
				structRectMerge.RightRect = rectStruct.nId;
				structRectMerge.nSign[3] = rectStruct.nSign[2];
			}
		}

		public static List<Curve> IsListCurveParking(Level level, List<Curve> lstBoundaryCvs, List<FamilyInstance> lstParkings, out FamilyInstance Parking)
		{
			Parking = null;
			foreach (FamilyInstance familyInstance in lstParkings)
			{
				Transform mat = familyInstance.GetTotalTransform();
				double num = 0.0;
				List<Curve> parkingSymbolCvs = AnalysisStruct.GetParkingSymbolCvs(familyInstance, ref num);
				if (parkingSymbolCvs == null)
				{
					return null;
				}
				List<Curve> lstTransCvs = new List<Curve>();
				parkingSymbolCvs.ForEach(delegate(Curve e)
				{
					Curve item = e.CreateTransformed(mat);
					lstTransCvs.Add(item);
				});
				foreach (Curve curve in lstBoundaryCvs)
				{
					YJKLine hyline = new YJKLine(curve as Line);
					foreach (Curve curve2 in lstTransCvs)
					{
						if (hyline.IntersectionPoint(curve2 as Line) != null)
						{
							Parking = familyInstance;
							return lstTransCvs;
						}
					}
				}
			}
			return null;
		}

		public static List<Curve> GetParkingSymbolCvs(FamilyInstance fiParking, ref double dWidth)
		{
			List<Curve> list = new List<Curve>();
			string name = fiParking.Symbol.Name;
			List<double> paraDouble = AnalysisStruct.GetParaDouble(fiParking);
			try
			{
				double num = paraDouble[0];
				dWidth = paraDouble[1];
				XYZ xyz = XYZ.Zero - XYZ.BasisX * dWidth * 0.5;
				xyz += XYZ.BasisY * num * 0.5;
				XYZ xyz2 = xyz + XYZ.BasisX * dWidth;
				XYZ xyz3 = xyz2 - XYZ.BasisY * num;
				XYZ xyz4 = xyz - XYZ.BasisY * num;
				Curve item = Line.CreateBound(xyz, xyz2);
				Curve item2 = Line.CreateBound(xyz2, xyz3);
				Curve item3 = Line.CreateBound(xyz3, xyz4);
				Curve item4 = Line.CreateBound(xyz4, xyz);
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
				list.Add(item4);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			return list;
		}

		private static List<double> GetParaDouble(FamilyInstance drant)
		{
			string paramName = "车位长";
			string paramName2 = "停车位宽度";
			List<double> list = new List<double>();
			double num = 0.0;
			double num2 = 0.0;
			Parameter parameter = drant.GetParameter(paramName);
			Parameter parameter2 = drant.GetParameter(paramName2);
			parameter = AnalysisStruct.GetSpecParameterByStr(drant.Parameters, "车位长");
			if (parameter == null)
			{
				parameter = AnalysisStruct.GetSpecParameterByStr(drant.Parameters, "长");
			}
			parameter2 = AnalysisStruct.GetSpecParameterByStr(drant.Parameters, "车位宽");
			if (parameter2 == null)
			{
				parameter2 = AnalysisStruct.GetSpecParameterByStr(drant.Parameters, "宽");
			}
			if (parameter == null || parameter2 == null)
			{
				ParameterSet parameters = drant.Symbol.Parameters;
				parameter = AnalysisStruct.GetSpecParameterByStr(parameters, "车位长");
				if (parameter == null)
				{
					parameter = AnalysisStruct.GetSpecParameterByStr(parameters, "长");
				}
				parameter2 = AnalysisStruct.GetSpecParameterByStr(parameters, "车位宽");
				if (parameter2 == null)
				{
					parameter2 = AnalysisStruct.GetSpecParameterByStr(parameters, "宽");
				}
				if (parameter != null && parameter2 != null)
				{
					num2 = parameter.AsDouble();
					num = parameter2.AsDouble();
				}
				if (num2 == 0.0 || num == 0.0)
				{
					string name = drant.Name;
					if (name.Contains("x"))
					{
						try
						{
							string[] array = name.Split(new char[]
							{
								'x'
							});
							num2 = double.Parse(array[0]) / 304.8;
							num = double.Parse(array[1]) / 304.8;
						}
						catch
						{
							num = 0.0;
							num2 = 0.0;
						}
					}
				}
			}
			list.Add(num2);
			list.Add(num);
			return list;
		}

		private static Parameter GetSpecParameterByStr(ParameterSet paramSet, string strValue)
		{
			Parameter result = null;
			foreach (object obj in paramSet)
			{
				Parameter parameter = (Parameter)obj;
				if (parameter.Definition.Name.Contains(strValue))
				{
					result = parameter;
				}
			}
			return result;
		}

		public static List<RectStruct> AnalysisRectRegions(List<List<Curve>> lstRoomRegion)
		{
			return AnalysisStruct.AnalysisRectRegions(AnalysisStruct.MergeAbnormityRoom(AnalysisStruct.AnalysisRegions(lstRoomRegion)));
		}

		public static List<RectStruct> MergeAbnormityRoom(List<RectStruct> lstRect)
		{
			return lstRect;
		}

		public static List<RectStruct> AnalysisRectRegions(List<RectStruct> lstRoomRegion)
		{
			foreach (RectStruct rectStruct in lstRoomRegion)
			{
				if (rectStruct.blRect && rectStruct.blMerge)
				{
					rectStruct.nSign.Clear();
					rectStruct.UpRect = AnalysisStruct.GetNRect(rectStruct.nId, rectStruct.LstCurve[0], lstRoomRegion);
					if (rectStruct.UpRect != 0)
					{
						rectStruct.nSign.Add(1);
					}
					else
					{
						rectStruct.nSign.Add(0);
					}
					rectStruct.DownRect = AnalysisStruct.GetNRect(rectStruct.nId, rectStruct.LstCurve[1], lstRoomRegion);
					if (rectStruct.DownRect != 0)
					{
						rectStruct.nSign.Add(1);
					}
					else
					{
						rectStruct.nSign.Add(0);
					}
					rectStruct.LeftRect = AnalysisStruct.GetNRect(rectStruct.nId, rectStruct.LstCurve[2], lstRoomRegion);
					if (rectStruct.LeftRect != 0)
					{
						rectStruct.nSign.Add(1);
					}
					else
					{
						rectStruct.nSign.Add(0);
					}
					rectStruct.RightRect = AnalysisStruct.GetNRect(rectStruct.nId, rectStruct.LstCurve[3], lstRoomRegion);
					if (rectStruct.RightRect != 0)
					{
						rectStruct.nSign.Add(1);
					}
					else
					{
						rectStruct.nSign.Add(0);
					}
				}
			}
			return lstRoomRegion;
		}

		private static int GetNRect(int id, Curve rect, List<RectStruct> temp)
		{
			foreach (RectStruct rectStruct in temp)
			{
				if (id != rectStruct.nId && AnalysisStruct.GetIDRect(rectStruct.LstCurve, rect))
				{
					return rectStruct.nId;
				}
			}
			return 0;
		}

		private static bool GetIDRect(List<Curve> temp, Curve rect)
		{
			YJKLine hyline = new YJKLine(rect.GetEndPoint(0), rect.GetEndPoint(1));
			foreach (Curve curve in temp)
			{
				YJKLine hyline2 = new YJKLine(curve.GetEndPoint(0), curve.GetEndPoint(1));
				if (hyline.IsParallel(hyline2.Line) && ((hyline.StartPoint.IsAlmostEqualTo(hyline2.StartPoint, 0.0001) && hyline.EndPoint.IsAlmostEqualTo(hyline2.EndPoint, 0.0001)) || (hyline.EndPoint.IsAlmostEqualTo(hyline2.StartPoint, 0.0001) && hyline.StartPoint.IsAlmostEqualTo(hyline2.EndPoint, 0.0001))))
				{
					return true;
				}
			}
			return false;
		}

		private static List<RectStruct> AnalysisRegions(List<List<Curve>> lstRoomRegion)
		{
			List<RectStruct> list = new List<RectStruct>();
			int num = 0;
			foreach (List<Curve> list2 in lstRoomRegion)
			{
				RectStruct rectStruct = new RectStruct();
				rectStruct.nId = num++;
				rectStruct.blRect = GroundStorehouseNozzle.GetBlRect(list2);
				if (rectStruct.blRect)
				{
					rectStruct.blMerge = GroundStorehouseNozzle.GetBlLess(list2);
					List<Curve> lstCurve = new List<Curve>();
					rectStruct.nSign = AnalysisStruct.AnaUDLR(list2, out lstCurve);
					rectStruct.LstCurve = lstCurve;
				}
				else
				{
					rectStruct.LstCurve = list2;
					rectStruct.blMerge = false;
					rectStruct.nSign = new List<int>
					{
						0,
						0,
						0,
						0
					};
				}
				rectStruct.UpRect = 0;
				rectStruct.DownRect = 0;
				rectStruct.LeftRect = 0;
				rectStruct.RightRect = 0;
				list.Add(rectStruct);
			}
			return list;
		}

		private static List<int> AnaUDLR(List<Curve> lst, out List<Curve> lstOut)
		{
			lstOut = new List<Curve>();
			List<int> list = new List<int>();
			bool flag = false;
			List<Curve> list2 = GroundStorehouseNozzle.SortListCurve(lst, out flag);
			double num = 7.8740157480314954;
			if (list2[3].GetEndPoint(0).DistanceTo(list2[3].GetEndPoint(1)) <= num)
			{
				list.Add(1);
			}
			else
			{
				list.Add(0);
			}
			if (list2[1].GetEndPoint(0).DistanceTo(list2[1].GetEndPoint(1)) <= num)
			{
				list.Add(1);
			}
			else
			{
				list.Add(0);
			}
			if (list2[0].GetEndPoint(0).DistanceTo(list2[0].GetEndPoint(1)) <= num)
			{
				list.Add(1);
			}
			else
			{
				list.Add(0);
			}
			if (list2[2].GetEndPoint(0).DistanceTo(list2[2].GetEndPoint(1)) <= num)
			{
				list.Add(1);
			}
			else
			{
				list.Add(0);
			}
			lstOut.Add(list2[0]);
			lstOut.Add(list2[2]);
			lstOut.Add(list2[3]);
			lstOut.Add(list2[1]);
			return list;
		}

		public static List<Curve> FilterOutArcCurves(List<Curve> lstCurves)
		{
			List<Curve> list = new List<Curve>();
			foreach (Curve curve in lstCurves)
			{
				if (curve is Line)
				{
					list.Add(curve);
				}
				else
				{
					XYZ endPoint = curve.GetEndPoint(0);
					XYZ endPoint2 = curve.GetEndPoint(1);
					Curve curve2 = Line.CreateBound(endPoint, endPoint2);
					if (curve is Arc)
					{
						Curve midUnboundCurve = AnalysisStruct.GetMidUnboundCurve(curve2);
						Arc arc = curve as Arc;
						IntersectionResultArray intersectionResultArray = new IntersectionResultArray();
						SetComparisonResult setComparisonResult = arc.Intersect(midUnboundCurve, out intersectionResultArray);
						if (4 != (int)setComparisonResult)
						{
							XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
							Curve curve3 = Line.CreateBound(endPoint, xyzpoint);
							Curve curve4 = Line.CreateBound(xyzpoint, endPoint2);
							IntersectionResultArray intersectionResultArray2 = new IntersectionResultArray();
							IntersectionResultArray intersectionResultArray3 = new IntersectionResultArray();
							Curve midUnboundCurve2 = AnalysisStruct.GetMidUnboundCurve(curve3);
							Curve midUnboundCurve3 = AnalysisStruct.GetMidUnboundCurve(curve4);
							SetComparisonResult setComparisonResult2 = arc.Intersect(midUnboundCurve2, out intersectionResultArray2);
							SetComparisonResult setComparisonResult3 = arc.Intersect(midUnboundCurve3, out intersectionResultArray3);
							XYZ xyz = xyzpoint;
							if (4 != (int)setComparisonResult2)
							{
								xyz = intersectionResultArray2.get_Item(0).XYZPoint;
							}
							XYZ xyz2 = xyzpoint;
							if (4 != (int)setComparisonResult3)
							{
								xyz2 = intersectionResultArray3.get_Item(0).XYZPoint;
							}
							Curve item = Line.CreateBound(endPoint, xyz);
							Curve item2 = Line.CreateBound(xyz, xyzpoint);
							Curve item3 = Line.CreateBound(xyzpoint, xyz2);
							Curve item4 = Line.CreateBound(xyz2, endPoint2);
							list.Add(item);
							list.Add(item2);
							list.Add(item3);
							list.Add(item4);
						}
					}
					else
					{
						list.Add(curve2);
					}
				}
			}
			return list;
		}

		private static Curve GetNormalVecLine(YJKLine originalLine)
		{
			XYZ xyz = originalLine.EndPoint - originalLine.StartPoint;
			XYZ xyz2 = originalLine.StartPoint.Add(xyz / 2.0);
			XYZ xyz3 = new XYZ(0.0, 0.0, 1.0).CrossProduct(xyz);
			XYZ end = xyz2.Add(xyz3);
			return new YJKLine(xyz2, end).Line;
		}

		public static Curve GetMidUnboundCurve(Curve curve)
		{
			YJKLine hyline = new YJKLine(AnalysisStruct.GetNormalVecLine(new YJKLine(curve as Line)) as Line);
			hyline.MakeUnBound();
			return hyline.Line;
		}
	}
}
